﻿// -------------------------------------------------------------------------
//    @FileName         :    NFWorldWelfareDBData.h
//    @Author           :    gaoyi
//    @Date             :    2025-07-10
//    @Email			:    445267987@qq.com
//    @Module           :    NFWorldWelfareDBData
//
// -------------------------------------------------------------------------

#pragma once

#include "NFWorldData.h"
#include "proto_svr_world.pb.h"
#include "proto_welfare.nanopb.h"
#include "NFComm/NFObjCommon/NFObject.h"
#include "NFLogicCommon/NFLogicShmTypeDefines.h"

struct E_Welfare;

class NFWorldWelfareDBData : public NF_OBJECT_GLOBAL_TEMPLATE_MACRO(NFWorldWelfareDBData, EOT_WORLD_WELFARE_DB_DATA_ID, NFWorldData)
public:
    NFWorldWelfareDBData();
    ~NFWorldWelfareDBData() override;
    int CreateInit();
    int ResumeInit();
    int OnTimer(int timeId, int callCount) override;
public:
    int Tick();
    int CheckOpenClose(WelfareDBWorldData* pWorldDBData);
    int DelOneWelfareBefore(WelfareDBWorldDataOne& stWelfareDBDataOne);
    int AddOneWelfare(WelfareDBWorldData* pWorldDBData, uint64_t welfareID);
    int InitOneWelfare(WelfareDBWorldDataOne& stWorldDBDataOne, const E_Welfare& stWelfare, uint32_t uiUpdateUnixSec = 0);
    int CheckSyncToGameSvr(WelfareDBWorldData* pWorldDBData, bool bForce = false);
    int SyncToGameSvr(WelfareDBWorldData* pWorldDBData, int iSvrID, int iSyncType);
    int GetWorldDBData(proto_ff::SSWorldWelfareSyncDBDataRes& res);
public:
    int InitDBData() override;
    void MarkDirty() override;
    uint32_t GetSaveDis() override { return 5; };
public:
    const WelfareDBWorldDataConfig* GetConfig() const;
    const WelfareDBWorldData* GetWelfareDB() const;
    WelfareDBWorldDataConfig* GetConfig();
    WelfareDBWorldData* GetWelfareDB();
private:
    bool m_bGSDirty;
    uint32_t m_uiSynGSSec;
};
